﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;

namespace AgendaManager.Service
{
    public class SemanaDAO : DAOBase
    {
        internal static List<Semana> RetrieveEntitiesWhere(object dto, string where)
        {
            List<Semana> dtos = new List<Semana>();

            DataTable dt = GetDataTableWhere(dto, where);

            if (dt.Rows.Count > 0)
                dtos = LlenarSemana(dto, dt);

            return dtos;
        }

        private static List<Semana> LlenarSemana(object dto, DataTable dt)
        {
            List<Semana> dtos = new List<Semana>();

            foreach (DataRow dr in dt.Rows)
            {
                Semana aux = new Semana();
                PoblarObjetoDesdeDataRow(aux, dr);

                dtos.Add(aux);
            }

            return dtos;
        }

        internal static bool NuevaSemana(Semana semana)
        {
            try
            {
                int semanaId = GetNextId(semana);

                if (semanaId != 0)
                {
                    semana.Id = semanaId;
                    if (CreateEntity(semana))
                    {
                        if (SubCarpetaDAO.NuevaSubCarpeta(semana))
                            return true;
                    }
                }

                return false;
            }
            catch (Exception)
            {

                throw;
            }
        }

        internal static bool UpdateEntity(object dto)
        {
            try
            {
                return DAOBase.UpdateEntity(dto);
            }
            catch (Exception)
            {
                throw;
            }
        }

    }
}